package org.nanotek.dao;

import java.io.Serializable;
import java.util.List;

import org.nanotek.Base;

public class GeneralPurposeDAO extends BaseDAO implements DAO<Base<?>> {

	public GeneralPurposeDAO() {}

	@Transactional (readOnly = false, propagation = Propagation.REQUIRED)
	public Base<?> findById (Serializable id)
	{ 
		Session session = getSessionFactory().getCurrentSession();
		return (Base<?>) session.get(clazz, id);
	}

	@Override
	@Transactional (readOnly = true, propagation = Propagation.REQUIRED)
	public List<Base<?>> listRecords(Integer firstResult, Integer maxResults) {
		try {
			Session session = getSessionFactory().getCurrentSession();
			Criteria criteria = session.createCriteria(clazz);
			return criteria.setFirstResult(firstResult).setMaxResults(maxResults).list();
		} catch (DataAccessException e) {
			throw new DAOException(e);
		}
	}
}
